from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-18 14:02:23.118302
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 18, Nov, 2022
Time: 14:02:29
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9793
Nobs: 844.000 HQIC: -51.2909
Log likelihood: 11038.2 FPE: 4.37076e-23
AIC: -51.4845 Det(Omega_mle): 3.93114e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299113 0.050549 5.917 0.000
L1.Burgenland 0.109763 0.034734 3.160 0.002
L1.Kärnten -0.106174 0.018505 -5.738 0.000
L1.Niederösterreich 0.210404 0.072641 2.896 0.004
L1.Oberösterreich 0.100600 0.069082 1.456 0.145
L1.Salzburg 0.251799 0.036833 6.836 0.000
L1.Steiermark 0.037223 0.048312 0.770 0.441
L1.Tirol 0.107613 0.039149 2.749 0.006
L1.Vorarlberg -0.060215 0.033756 -1.784 0.074
L1.Wien 0.054084 0.061755 0.876 0.381
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.067492 0.104251 0.647 0.517
L1.Burgenland -0.030331 0.071636 -0.423 0.672
L1.Kärnten 0.047614 0.038165 1.248 0.212
L1.Niederösterreich -0.173889 0.149815 -1.161 0.246
L1.Oberösterreich 0.379221 0.142475 2.662 0.008
L1.Salzburg 0.288488 0.075963 3.798 0.000
L1.Steiermark 0.107821 0.099639 1.082 0.279
L1.Tirol 0.315827 0.080741 3.912 0.000
L1.Vorarlberg 0.022967 0.069619 0.330 0.741
L1.Wien -0.018879 0.127364 -0.148 0.882
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197279 0.026165 7.540 0.000
L1.Burgenland 0.092470 0.017979 5.143 0.000
L1.Kärnten -0.008772 0.009579 -0.916 0.360
L1.Niederösterreich 0.267929 0.037601 7.126 0.000
L1.Oberösterreich 0.115031 0.035758 3.217 0.001
L1.Salzburg 0.052640 0.019065 2.761 0.006
L1.Steiermark 0.016520 0.025007 0.661 0.509
L1.Tirol 0.098442 0.020264 4.858 0.000
L1.Vorarlberg 0.056220 0.017473 3.218 0.001
L1.Wien 0.113277 0.031966 3.544 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104961 0.026829 3.912 0.000
L1.Burgenland 0.047166 0.018435 2.558 0.011
L1.Kärnten -0.017243 0.009822 -1.756 0.079
L1.Niederösterreich 0.196778 0.038555 5.104 0.000
L1.Oberösterreich 0.279932 0.036666 7.635 0.000
L1.Salzburg 0.120192 0.019549 6.148 0.000
L1.Steiermark 0.101728 0.025642 3.967 0.000
L1.Tirol 0.123373 0.020778 5.938 0.000
L1.Vorarlberg 0.069150 0.017916 3.860 0.000
L1.Wien -0.026770 0.032777 -0.817 0.414
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130478 0.048596 2.685 0.007
L1.Burgenland -0.049425 0.033392 -1.480 0.139
L1.Kärnten -0.039439 0.017790 -2.217 0.027
L1.Niederösterreich 0.167317 0.069835 2.396 0.017
L1.Oberösterreich 0.139557 0.066413 2.101 0.036
L1.Salzburg 0.285222 0.035409 8.055 0.000
L1.Steiermark 0.032755 0.046445 0.705 0.481
L1.Tirol 0.163076 0.037636 4.333 0.000
L1.Vorarlberg 0.103861 0.032452 3.200 0.001
L1.Wien 0.068272 0.059369 1.150 0.250
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059009 0.038481 1.533 0.125
L1.Burgenland 0.042570 0.026442 1.610 0.107
L1.Kärnten 0.049811 0.014087 3.536 0.000
L1.Niederösterreich 0.227880 0.055299 4.121 0.000
L1.Oberösterreich 0.272132 0.052590 5.175 0.000
L1.Salzburg 0.058183 0.028039 2.075 0.038
L1.Steiermark -0.006895 0.036778 -0.187 0.851
L1.Tirol 0.156355 0.029803 5.246 0.000
L1.Vorarlberg 0.068018 0.025697 2.647 0.008
L1.Wien 0.073450 0.047012 1.562 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184933 0.046067 4.014 0.000
L1.Burgenland -0.004524 0.031655 -0.143 0.886
L1.Kärnten -0.060966 0.016865 -3.615 0.000
L1.Niederösterreich -0.086917 0.066201 -1.313 0.189
L1.Oberösterreich 0.191899 0.062958 3.048 0.002
L1.Salzburg 0.059624 0.033567 1.776 0.076
L1.Steiermark 0.225748 0.044029 5.127 0.000
L1.Tirol 0.494962 0.035678 13.873 0.000
L1.Vorarlberg 0.047683 0.030763 1.550 0.121
L1.Wien -0.050425 0.056280 -0.896 0.370
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158501 0.052474 3.021 0.003
L1.Burgenland -0.009179 0.036058 -0.255 0.799
L1.Kärnten 0.064691 0.019210 3.368 0.001
L1.Niederösterreich 0.202659 0.075408 2.687 0.007
L1.Oberösterreich -0.067544 0.071714 -0.942 0.346
L1.Salzburg 0.222782 0.038235 5.827 0.000
L1.Steiermark 0.113392 0.050152 2.261 0.024
L1.Tirol 0.084206 0.040640 2.072 0.038
L1.Vorarlberg 0.121925 0.035042 3.479 0.001
L1.Wien 0.110277 0.064107 1.720 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356700 0.030928 11.533 0.000
L1.Burgenland 0.008737 0.021252 0.411 0.681
L1.Kärnten -0.024808 0.011322 -2.191 0.028
L1.Niederösterreich 0.227711 0.044446 5.123 0.000
L1.Oberösterreich 0.157770 0.042268 3.733 0.000
L1.Salzburg 0.053233 0.022536 2.362 0.018
L1.Steiermark -0.018287 0.029560 -0.619 0.536
L1.Tirol 0.117537 0.023953 4.907 0.000
L1.Vorarlberg 0.071847 0.020654 3.479 0.001
L1.Wien 0.050874 0.037785 1.346 0.178
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043820 0.161053 0.192769 0.165684 0.131937 0.124328 0.070052 0.230843
Kärnten 0.043820 1.000000 0.001703 0.131623 0.045222 0.099488 0.427808 -0.050902 0.101750
Niederösterreich 0.161053 0.001703 1.000000 0.345729 0.166717 0.311635 0.127709 0.191910 0.340667
Oberösterreich 0.192769 0.131623 0.345729 1.000000 0.235846 0.340961 0.177954 0.180369 0.276023
Salzburg 0.165684 0.045222 0.166717 0.235846 1.000000 0.153414 0.145263 0.152825 0.140269
Steiermark 0.131937 0.099488 0.311635 0.340961 0.153414 1.000000 0.163398 0.148623 0.092716
Tirol 0.124328 0.427808 0.127709 0.177954 0.145263 0.163398 1.000000 0.121920 0.164046
Vorarlberg 0.070052 -0.050902 0.191910 0.180369 0.152825 0.148623 0.121920 1.000000 0.019489
Wien 0.230843 0.101750 0.340667 0.276023 0.140269 0.092716 0.164046 0.019489 1.000000